<template>
  <div class="addUrl">
    <div class="addUrl-opera">
      <van-button type="default" size="mini" @click="useOperatorBoxStore().showOverlay(false, '')">取消</van-button>
      <span>添加网址</span>
      <van-button type="primary" size="mini" @click="handleClick">完成</van-button>
    </div>
    <div class="addUrl-content">
      <van-field
          v-model="data.message"
          rows="2"
          autosize
          type="textarea"
          maxlength="250"
          placeholder="输入或粘贴网址 https://"
          show-word-limit
      />
    </div>
  </div>
</template>

<script setup>
// 作者：YCH
// 时间：2023年2月16日 22:31:06
import {reactive, ref} from "vue";
import useOperatorBoxStore from "@/stores/modules/operatorBox.js";
import {addCrawler} from "@/api/crawler/crawler.js";
import {showToast} from "vant";

const data = new reactive({
  message: ''
})
const onSearch = (val) => {
  console.log(val)
};

const handleClick = () => {
  if (data.message == null || data.message == '') {
    console.log(data.message)
    return;
  }
  let objExp = new RegExp(/^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\*\+,;=.]+$/);
  if (!objExp.test(data.message)) {
    return;
  } else {
    addCrawler({url: data.message}).then(res => {
      useOperatorBoxStore().showOverlay(false, '');
      showToast("添加成功！");
    })
  }
}

</script>

<style lang="less" scoped>
.addUrl {
  position: relative;
  padding: 10px 12px;
  font-family: var(--primary-font-family);
  font-weight: bold;
  color: var(--primary-font-color);

  .addUrl-opera {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .addUrl-content {
    margin-top: 10px;

    .van-cell.van-field {
      border-radius: 4px;
      background-color: var(--primary-background-color);
    }
  }


}
</style>
